/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 23-sep-2011, 22:48:51
 */
package ventanas;

/**
 *
 * @author Franco
 */
import java.awt.Component;
import java.awt.event.*;

import javax.swing.DefaultListModel;
import tsb_tp1.*;

public class Principal extends javax.swing.JFrame {

    public LinkedList getPaises() {
        return paises;
    }

    public void setPaises(LinkedList paises) {
        this.paises = paises;
    }

    public LinkedList getPaisesOcupados() {
        return paisesOcupados;
    }

    public void setPaisesOcupados(LinkedList paisesOcupados) {
        this.paisesOcupados = paisesOcupados;
    }

    public LinkedList getUnidades() {
        return unidades;
    }

    public void setUnidades(LinkedList unidades) {
        this.unidades = unidades;
    }

    public LinkedList getUnidadesMayores() {
        return unidadesMayores;
    }
    
    public void agregarPais()
    {
        DefaultListModel modelo = new DefaultListModel();  
        for(int i = 0; i<paises.size(); i++){ 
         modelo.addElement(paises.get(i)); 
         
        }  
        lstPaises.setModel(modelo);  
    }

    public void setUnidadesMayores(LinkedList unidadesMayores) {
        this.unidadesMayores = unidadesMayores;
    }
    
     LinkedList paises;
     LinkedList unidades;
     LinkedList unidadesMayores;
     LinkedList paisesOcupados;

    /** Creates new form Principal */
    public Principal() {
        initComponents();
        paises=new LinkedList();
        unidades=new LinkedList();
        unidadesMayores=new LinkedList();
        paisesOcupados=new LinkedList();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        pnlBotones = new javax.swing.JPanel();
        btnAgregarPais = new javax.swing.JButton();
        btnAgregarUnidad = new javax.swing.JButton();
        btnMostrarPaisesOcupados = new javax.swing.JButton();
        pnlPestañas = new javax.swing.JTabbedPane();
        pnlPaises = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstPaises = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtPaises = new javax.swing.JTextArea();
        pnlUnidades = new javax.swing.JSplitPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstUnidades = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        txtUnidades = new javax.swing.JTextArea();
        pnlUnidMay5 = new javax.swing.JSplitPane();
        jScrollPane5 = new javax.swing.JScrollPane();
        lstUnidMay5 = new javax.swing.JList();
        jScrollPane6 = new javax.swing.JScrollPane();
        txtUnidMay5 = new javax.swing.JTextArea();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        mainPanel.setLayout(new javax.swing.BoxLayout(mainPanel, javax.swing.BoxLayout.PAGE_AXIS));

        btnAgregarPais.setText("Agregar Pais");
        btnAgregarPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarPaisActionPerformed(evt);
            }
        });

        btnAgregarUnidad.setText("Agregar Unidad Militar");
        btnAgregarUnidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarUnidadActionPerformed(evt);
            }
        });

        btnMostrarPaisesOcupados.setText("Mostrar Paises Ocupados");
        btnMostrarPaisesOcupados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMostrarPaisesOcupadosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBotonesLayout = new javax.swing.GroupLayout(pnlBotones);
        pnlBotones.setLayout(pnlBotonesLayout);
        pnlBotonesLayout.setHorizontalGroup(
            pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(btnAgregarPais)
                    .addComponent(btnAgregarUnidad)
                    .addComponent(btnMostrarPaisesOcupados))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlBotonesLayout.setVerticalGroup(
            pnlBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBotonesLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(btnAgregarPais, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnAgregarUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnMostrarPaisesOcupados, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(303, Short.MAX_VALUE))
        );

        jSplitPane1.setLeftComponent(pnlBotones);

        jScrollPane1.setViewportView(lstPaises);

        pnlPaises.setLeftComponent(jScrollPane1);

        txtPaises.setColumns(20);
        txtPaises.setRows(5);
        jScrollPane2.setViewportView(txtPaises);

        pnlPaises.setRightComponent(jScrollPane2);

        pnlPestañas.addTab("Paises", pnlPaises);

        jScrollPane3.setViewportView(lstUnidades);

        pnlUnidades.setLeftComponent(jScrollPane3);

        txtUnidades.setColumns(20);
        txtUnidades.setRows(5);
        jScrollPane4.setViewportView(txtUnidades);

        pnlUnidades.setRightComponent(jScrollPane4);

        pnlPestañas.addTab("Unidades Militares", pnlUnidades);

        jScrollPane5.setViewportView(lstUnidMay5);

        pnlUnidMay5.setLeftComponent(jScrollPane5);

        txtUnidMay5.setColumns(20);
        txtUnidMay5.setRows(5);
        jScrollPane6.setViewportView(txtUnidMay5);

        pnlUnidMay5.setRightComponent(jScrollPane6);

        pnlPestañas.addTab("Unidades con poder mayor a 5", pnlUnidMay5);

        jSplitPane1.setRightComponent(pnlPestañas);

        mainPanel.add(jSplitPane1);

        jMenu1.setText("Archivo");

        jMenuItem2.setText("Salir");
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Ayuda");

        jMenuItem1.setText("Acerca de...");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 814, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarPaisActionPerformed
       final AgregarPais ap=new AgregarPais(this, true);
       ap.setVisible(true);
       ap.addWindowListener(new  WindowAdapter() {@Override
       public void windowClosed(WindowEvent e) {
		paises.addLinkedList(ap.getPaises());
                agregarPais();
                System.out.println(paises.toString());
                
			}
      
       });

            
		

    }//GEN-LAST:event_btnAgregarPaisActionPerformed

    private void btnAgregarUnidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarUnidadActionPerformed
        AgregarUnidadMilitar aum=new AgregarUnidadMilitar(this, true);
       aum.setVisible(true);
    }//GEN-LAST:event_btnAgregarUnidadActionPerformed

    private void btnMostrarPaisesOcupadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMostrarPaisesOcupadosActionPerformed
       MostrarPaisesOcupados mpo=new MostrarPaisesOcupados(this, true);
       mpo.setVisible(true);
    }//GEN-LAST:event_btnMostrarPaisesOcupadosActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarPais;
    private javax.swing.JButton btnAgregarUnidad;
    private javax.swing.JButton btnMostrarPaisesOcupados;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JList lstPaises;
    private javax.swing.JList lstUnidMay5;
    private javax.swing.JList lstUnidades;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JPanel pnlBotones;
    private javax.swing.JSplitPane pnlPaises;
    private javax.swing.JTabbedPane pnlPestañas;
    private javax.swing.JSplitPane pnlUnidMay5;
    private javax.swing.JSplitPane pnlUnidades;
    private javax.swing.JTextArea txtPaises;
    private javax.swing.JTextArea txtUnidMay5;
    private javax.swing.JTextArea txtUnidades;
    // End of variables declaration//GEN-END:variables
}
